import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';

/**
 * StatefulWidget与基础组件
 */
class StateFullGroupPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => _StateFullGroupState();
}

class _StateFullGroupState extends State<StateFullGroupPage>{
  int _currIndex = 0;


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'StatefulWidget与基础组件',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('StatelessWidget与基础组件'),
            backgroundColor: ColorUtil.color("#fe45dd"),
            leading: GestureDetector( //AppBar 左边加返回图标实现返回上一页面
              child: Icon(Icons.arrow_back),
              onTap: (){
                Navigator.pop(context);
              },
            ),
          ),
          bottomNavigationBar: BottomNavigationBar(onTap: (index)=> setState((){
            _currIndex = index;
          }),
            currentIndex: _currIndex,
            items: [
            BottomNavigationBarItem(icon: Icon(Icons.home, color: Colors.grey),
            activeIcon: Icon(Icons.home, color: Colors.blue), title: Text("首页")),
            BottomNavigationBarItem(icon: Icon(Icons.list, color: Colors.grey),
                activeIcon: Icon(Icons.list, color: Colors.blue), title: Text("列表")),
          ],),
          floatingActionButton: FloatingActionButton(
            child: Text("点我"),
          ),
          body: _currIndex == 0 ? RefreshIndicator(child: ListView(children: <Widget>[  //RefreshIndicator 组件
            Image.network("http://www.devio.org/img/avatar.png",width:50, height: 50), //Image 组件
            TextField(  //TextField 组件
              //输入框样式
              decoration: InputDecoration(contentPadding: EdgeInsets.fromLTRB(5, 0, 0, 0),
                hintText: '请输入姓名',
                hintStyle: TextStyle(fontSize: 15)
              ),
            ),
            Container(
              height: 100,
              margin: EdgeInsets.only(top:10),
              decoration: BoxDecoration(color: Colors.lightBlueAccent),
              child: PageView(  //PageView 组件
                children: <Widget>[
                  _item('Page1', Colors.deepPurple),
                  _item('Page2', Colors.deepOrange),
                  _item('Page3', Colors.blueAccent),
                ],
              ),
            )
          ]) , onRefresh: _handleRefresh)
              : Text('列表页面')
        )
    );
  }

   Future<Null> _handleRefresh()  async{
    await Future.delayed(Duration(milliseconds: 200));
    return null;
  }

  _item(String s, Color color) {
    return Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(color: color ),
      child: Text(s, style: TextStyle(fontSize: 22, color: Colors.white),),
    );
  }
}